package com.wxzz.elearing.livetelecast.api.server;

import com.wxzz.elearing.livetelecast.entity.LivePushCallbackEntity;
import com.wxzz.elearing.livetelecast.entity.LiveRecordCallbackEntity;
import com.wxzz.elearing.livetelecast.service.ILivetelecastRecordService;
import com.wxzz.elearing.livetelecast.service.IPlatformLivetelecastService;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/live-callback-api")
@Api(tags = "华为云回调(后台)")
public class LiveCallbackApi {

    @Autowired
    private ILivetelecastRecordService livetelecastRecordService;

    @Autowired
    private IPlatformLivetelecastService platformLivetelecastService;

    /**
     * 直播录制回调
     * @param callbackEntity
     * @return
     */
    @ApiOperation(value = "直播录制状态回调(后台)", notes = "直播录制状态回调(后台)", httpMethod = "POST", tags = "后台回调")
    @RequestMapping(value = "liveRecordCallback", method = RequestMethod.POST)
    public ReturnVO<String> liveRecordCallback(@RequestBody(required = true) LiveRecordCallbackEntity callbackEntity) {
        Boolean res = livetelecastRecordService.saveRecordByCallback(callbackEntity);
        return res ? new ReturnVO("直播录制回调成功", null) : new ReturnVO("直播录制回调失败", null);
    }

    // 开播停播回调
    @ApiOperation(value = "直播推流状态回调(后台)", notes = "直播推流状态回调(后台)", httpMethod = "POST", tags = "后台回调")
    @RequestMapping(value = "livePushCallback", method = RequestMethod.POST)
    public ReturnVO<String> livePushCallback(@RequestBody(required = true) LivePushCallbackEntity callbackEntity) {
        Boolean res = platformLivetelecastService.livePushCallback(callbackEntity);
        return res ? new ReturnVO("直播推流状态回调成功", null) : new ReturnVO("直播推流状态回调失败", null);
    }


}
